home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Gekikoh Dennoh Club 1
/
Gekikoh Dennoh Club Vol. 1 (Japan).7z
/
Gekikoh Dennoh Club Vol. 1 (Japan) (Track 1).bin
/
kowin
/
archive
/
apl
/
tvv132.lzh
/
readfile.c
< prev
next >
Wrap
C/C++ Source or Header
|
1995-12-27
|
4KB
|
193 lines
/*
MicroView.win Copyright 1995 小笠原博之
oga@dgw.yz.yamagata-u.ac.jp
*/
#include "microview.h"
#define Print(msg) ConsoleAutoPrint(msg)
#define FOFF 1024
#define Ctrl(a) ((a)&0x1f)
static unsigned char _KanjiC[]= {
0,0,0,0,0,0,0,0, 0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0, 0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0, 0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0, 0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0, 0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0, 0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0, 0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0, 0,0,0,0,0,0,0,0,
1,1,1,1,1,1,1,1, 1,1,1,1,1,1,1,1,
1,1,1,1,1,1,1,1, 1,1,1,1,1,1,1,1,
0,0,0,0,0,0,0,0, 0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0, 0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0, 0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0, 0,0,0,0,0,0,0,0,
1,1,1,1,1,1,1,1, 1,1,1,1,1,1,1,1,
1,1,1,1,0,0,0,0, 0,0,0,0,0,0,0,0,
};
static unsigned char *
skipnum( ptr )
unsigned char *ptr;
{
for(; *ptr >= '0' && *ptr <= '9' ; ptr++ );
return ptr;
}
static int
nn_numstr( ptr )
unsigned char *ptr;
{
int i= 0;
for(; *ptr >= '0' && *ptr <= '9' ; i*= 10, i+= (*ptr++&15) );
return i;
}
static unsigned char *
MakeBuf( bp, size )
T_BUFP *bp;
{
unsigned char *ptr= (unsigned char*)(bp->lp)+ FOFF,
*last= ptr+ size,
*str= bp->fbuf,
**lp= bp->lp;
int font= 12, attr= AttrDefault, option= 0;
int line;
for( line= 0 ; ptr < last ; ){
unsigned char kanji= 0;
int col;
if( *ptr == Ctrl('F') ){
bp->font_z= nn_numstr( ptr+1 );
goto __Cont;
}else if( *ptr == Ctrl('A') ){
bp->attr= nn_numstr( ptr+1 );
bp->backattr= bp->attr & AttrReverse ? bp->attr&3:0;
goto __Cont;
}else if( *ptr == Ctrl('T') ){
s_strcpych( '\r', bp->title, ptr+1 );
goto __Cont;
}else if( *ptr == Ctrl('P') ){
bp->x= nn_numstr( ptr+1 );
ptr= skipnum( ptr+1 );
bp->y= nn_numstr( ptr+1 );
ptr= skipnum( ptr+1 );
if( *ptr == ',' ){
int rnd= nn_numstr( ptr+1 );
bp->x+= RAND()%rnd;
bp->y+= RAND()%rnd;
}
goto __Cont;
}else if( *ptr == Ctrl('W') ){
bp->h= nn_numstr( ptr+1 );
bp->v= nn_numstr( s_strchr( ',', ptr+1 )+1 );
goto __Cont;
}else if( *ptr == Ctrl('_') ){
if( ptr[1] < ' ' ){
attr= 9;
font= 12;
option= 0;
}else{
font= nn_numstr( ptr+1 );
ptr= skipnum( ptr+1 );
if( *ptr == ',' ){
attr= nn_numstr( ptr+1 );
ptr= skipnum( ptr+1 );
if( *ptr == ',' )
option= nn_numstr( ptr+1 );
}
}
__Cont:
for(; *ptr++ != '\n' ;);
continue;
}
*lp++= str;
*str++= font;
*str++= option +1;
*str++= attr;
for( col= 0 ; col < bp->maxcol ;){
if( *ptr < ' ' ){
if( *ptr == '\t' ){
int l= bp->tabsize-(col&bp->tabmask);
for( ptr++,col+=l; l-- ; *str++= ' ');
continue;
}else if( *ptr == '\n' ){
ptr++;
break;
}else if( *ptr == '\r' ){
___cr:
if( ptr[1] == '\n' )
ptr++;
ptr++;
break;
}else if( *ptr == Ctrl('X') ){
*str++= '\0';
ptr++;
for(; *ptr != '\r' ; *str++= *ptr++ );
goto ___cr;
}
}
kanji= kanji ? 0 : _KanjiC[*ptr];
*str++= *ptr++;
col++;
}
if( kanji ){
str--;
ptr--;
}
*str++= '\0';
line++;
}
bp->line= line;
bp->curpos= -1;
return str;
}
static
FileLoad( fn, bp)
T_BUFP *bp;
{
int fsize= SEEK( fn, 0, 2 );
SEEK( fn, 0, 0 );
if( (int)(bp->lp= MALLOC( fsize+FOFF )) < 0 ){
CLOSE( fn );
Print( "tvv:alloc err\r\n" );
return 0;
}
READ( fn, (char*)(bp->lp)+FOFF, fsize );
CLOSE( fn );
if( (int)(bp->fbuf= MALLOC( fsize*2 )) < 0 ){
Print( "tvv:alloc err\r\n" );
return 0;
}
fsize= MakeBuf( bp, fsize )-bp->fbuf;
SETBLOCK( bp->fbuf, fsize );
SETBLOCK( bp->lp, sizeof(char*)*bp->line );
return fsize;
}
ReadFile( fname, bp, path )
char *fname, *path;
T_BUFP *bp;
{
int fn;
unsigned char buf[98],
*p= path;
if( *fname == '/' || fname[1] == ':' ){
if( (fn= OPEN( fname, 0 )) >= 0 )
return FileLoad( fn, bp );
}
for(; *p ; p++ ){
p= p_strcpych( ';', buf, p );
s_strcpy( s_strpath( buf ), fname );
if( (fn= OPEN( buf, 0 )) >= 0 )
return FileLoad( fn, bp );
}
Print( fname );
Print( ":tvv open err\r\n" );
return 0;
}